package com.example.quartz.job;

import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * 示例定时任务
 */
@Component
public class SampleJob implements Job {
    private static final Logger logger = LoggerFactory.getLogger(SampleJob.class);
    private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException {
        String jobName = context.getJobDetail().getKey().getName();
        String jobGroup = context.getJobDetail().getKey().getGroup();
        String currentTime = LocalDateTime.now().format(formatter);
        
        logger.info("=== SampleJob 执行 ===");
        logger.info("当前时间: {}", currentTime);
        logger.info("任务名称: {}", jobName);
        logger.info("任务组: {}", jobGroup);
        logger.info("======================");
    }
}
    